package utils;

import java.util.*;

public class HTMLTransformer {
	
	private static String htmlBlock;
	
	public static String convert2HTML(String tagName, String content, boolean etiqcierre){
		htmlBlock = "<" + tagName;
		if(!etiqcierre){
			htmlBlock += "/>";
			
		}else{
			htmlBlock += ">";
			if(content != null && content.length() > 0){
				htmlBlock += content;
			}
			htmlBlock += "</" + tagName + ">";
			
		}
		/*System.out.println("###############################");
		System.out.println(htmlBlock);
		System.out.println("###############################");*/
		return htmlBlock;
	}
	
	public static String convert2HTML(String tagName, String content, List atribs, List values, boolean etiqcierre){
		
		htmlBlock = "<" + tagName;
		Iterator ita = atribs.iterator();
		Iterator itv = values.iterator();
		
		while(ita.hasNext()){
			String atribAux = (String)ita.next();
			String valAux = (String)itv.next();
			htmlBlock += " " + atribAux + "=" + quote(valAux);
		}
		
		if(!etiqcierre){
			htmlBlock += "/>";
			return htmlBlock;
		}else{
			htmlBlock += ">";
			if(content != null && content.length() > 0){
				htmlBlock += content;
			}
			htmlBlock += "</" + tagName + ">";
			return htmlBlock;
		}
		
		
	}
	
	public static String quote(String s){
		return "\"" + s + "\"";
	}

	public static String getHtmlBlock() {
		return htmlBlock;
	}
	
}

